<?php

/**
 * Nominee form.
 *
 * @package    lomejorde
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class NomineeForm extends BaseNomineeForm
{
    public function configure()
    {
        unset($this['created_at'], $this['updated_at']);

        $this->widgetSchema['category_id'] = new sfWidgetFormInputHidden();

        $this->widgetSchema['candidate_id'] = new sfWidgetFormInputHidden();

        $this->widgetSchema['autocomplete_input'] = new sfWidgetFormInput(
                array('label' => 'Nominado'), 
                array('class' => 'ac_input'));
    }
    
    public function bind(array $taintedValues = null, array $taintedFiles = null)
    {
        if($taintedValues['autocomplete_input'] != '' &&
             ($taintedValues['candidate_id'] == '' || !Doctrine::getTable('Candidate')->findOneBy('name', $taintedValues['autocomplete_input']))){
            return false;
        } else {
            unset($taintedValues['autocomplete_input']);
        
            parent::bind($taintedValues, $taintedFiles);

            return true;
        }
    }
}
